{include file="public/header"/}
{load href="/public/static/Content/ThemesBusiness/FormPage.css"}

<div id="tabState" class="easyui-tabs" fit="true">
    <div title="资料上传">
        <form id="formState">
            <table class="form_table" style="width:860px">
                <tr class="form_tr">
                    <th style="padding-left:8px;width:80px;" class="form_td form_th_title">
                        商品系列
                    </th>
                    <td style="width:600px;padding-left:8px;" colspan="4" class="form_td form_td_content">
                        <select class="easyui-combobox" id="pid" name="pid"
                            data-options="required:true,tipPosition:'right'," style="width:150px;">
                            <option value="0">选择系列</option>
                            {volist name="$series" id="vo"}
                            <!-- <option value="{$vo.id}">{$vo.name}</option> -->
                            <option value="{$vo.id}" {if condition="$vo.id eq $info.pid" } selected {/if}>{$vo.name}</option>
                            {/volist}
                        </select>
                    </td>
                </tr>

                <tr class="form_tr">
                    <th style="padding-left:8px;width:80px;" class="form_td form_th_title">
                        资料名称
                    </th>
                    <td style="width:90%;padding-left:8px;" colspan="4" class="form_td form_td_content">
                        <input class="easyui-validatebox" type="text" id="name" style="width: calc(100% - 16px);"
                            name="name" value="{$info.name}" data-options="required:true,tipPosition:'right'," />
                    </td>
                </tr>

                <tr class="form_tr">
                    <th style="padding-left:8px;" class="form_td form_th_title">
                        上传文件
                    </th>
                    <td>
                        <div style="margin-left: 8px;" id="form_ProductImg_UploadPanel">
                            <input type="file" id="file_sn">
                        </div>
                    </td>
                </tr>

                <tr class="form_tr">
                    <td class="form_button_panel" colspan="3" style="padding-right:8px">
                        <a id="save" class="easyui-linkbutton form-toolbar-button"
                            data-options="iconCls:'icon-save'">保存</a>
                    </td>
                    <td class="form_button_panel" colspan="3" style="padding-right:8px">
                    </td>
                </tr>
                <input type="hidden" name="url" id="url" value="">
                <input type="hidden" name="ext" id="ext" value="">
                <input type="hidden" name="size" id="size" value="">
                <input type="hidden" name="id" id="id" value="{$info.id}">
            </table>
        </form>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/exif-js"></script>

<script>

    document.getElementById("file_sn").addEventListener("change", function (e) {
        var formData = new FormData();
        formData.append('file', document.getElementById('file_sn').files[0]);
        $.ajax({
            url: '/api/upload/uploads.html?path=series_data',
            dataType: 'json',
            type: 'POST',
            async: false,
            data: formData,
            processData: false, // 使数据不做处理
            contentType: false, // 不要设置Content-Type请求头
            success: function (res) {
                console.log(res.img);
                if (res.status == 1) {
                    $.messager.alert('提示', res.msg, 'ok');
                    $('#url').val(res.info);
                    $('#ext').val(res.ext);
                    $('#size').val(res.size);
                } else {
                    $.messager.alert('提示', res.msg, 'error');
                }

            },
            error: function (response) {
                //$("#logo_img").val('');
                $.messager.alert('提示', '接口错误', 'error');
            }
        });
    });


    $(function () {
        $("#save").on("click", function () {
            var name = $('#name').val()
            if (name == '') {
                alert('请先添加名称');
                return false;
            }

            $.ajax({
                type: 'POST',
                url: "uploads_data.html",
                data: $("#formState").serialize(),
                dataType: "json",
                async: false,
                error: function (request) {
                    alert("发送请求失败！");
                },
                success: function (data) {
                    if (data.status == 1) {
                        alert(data.msg);
                        closeRefreshDialog();
                    } else {
                        // $.messager.alert('提示', data.msg, 'info');
                        // return;
                        alert(data.msg);
                    }
                }
            });
        })
    })


</script>

{include file="public/footer"/}